package com.jason.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jason.model.EbComment;
import com.jason.service.CommentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
@RequestMapping("comment")
public class CommentController {
    @Resource
    private CommentService commentService;

    @RequestMapping("list")
    public  String list(Model model,
                        @RequestParam(value = "psize",defaultValue = "1") int psize){
        System.out.println("进入CommentController的list方法.....");
        //1.调用service获取分页的留言信息列表
        Page commentPage = commentService.list(psize);
        //2.绑定数据到model
        model.addAttribute("commentPage",commentPage);
        //3.返回 view ----templates/guestbook.html
        return "guestbook";
    }
    @RequestMapping("/add")
    public  String add(EbComment ebComment){
        //1.调用service添加新闻
        boolean result = commentService.save(ebComment);
        //2.绑定数据 ？--不需要
        //3.返回view---guest-book.html
        if(result){
            return "redirect:list";
        }else{
            return "error";//templates/error.html
        }

    }


}
